<template>
  <div class="order-wrapper">
    <div class="search-container">
      <div class="order-num-container search-item">
        <div class="title">用户：</div>
        <el-input v-model="username" type="text" placeholder="请输入用户" class="input-container" />
      </div>
      <el-button type="primary" class="search-button" @click="handleSearch">搜索</el-button>
    </div>
    <el-table ref="multipleTable" v-loading="loading" :data="tableData" border tooltip-effect="dark" style="width: 100%">
      <el-table-column prop="username" label="用户" min-width="150" />
      <el-table-column prop="amount" label="储值总额（元）" min-width="150" />
      <el-table-column prop="total_give_amount" label="赠送总额（元）" min-width="150" />
      <el-table-column prop="total_real_amount" label="支付金额（元）" min-width="150" />
      <el-table-column fixed="right" label="操作" min-width="300">
        <template slot-scope="scope">
          <el-button type="primary" @click="handledetail(scope)">储值列表</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>listQuery.limit" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
    <router-view />
  </div>
</template>

<script>
import { storevalueOrderList } from '@/api/order'
import Pagination from '@/components/Pagination'
import { parseTime } from '@/utils'
export default {
  name: 'OrderList',
  components: {
    Pagination
  },
  props: {
    type: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      username: '',
      loading: false,
      total: 0,
      listQuery: {
        page: 1,
        limit: 10
      },
      list: []
    }
  },
  computed: {
    tableData() {
      return this.list.map((item) => {
        item.start_at = item.start_at ? parseTime(item.start_at) : ''
        item.end_at = item.end_at ? parseTime(item.end_at) : ''
        return item
      })
    }
  },
  created() {
    this.initList()
  },
  methods: {
    // 分页
    getList(prop) {
      this.listQuery.page = prop.page
      this.listQuery.limit = prop.limit
      this.initList()
    },
    async initList() {
      this.loading = true
      const { username } = this
      const { page, limit } = this.listQuery
      const res = await storevalueOrderList({ username, page, limit })
      this.loading = false
      const { total, lists } = res.data
      this.total = total
      this.list = lists
    },
    handleSearch() {
      this.initList()
    },
    handledetail(scope) {
      const { uid } = scope.row
      this.$router.push({
        path: `/order/storeValue/OrderDetail`,
        query: {
          uid
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.order-wrapper {
  width: 100%;
  height: 100%;
  padding: 20px;
  z-index: 10;
  box-sizing: border-box;
  .search-container{
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    margin-bottom: 20px;
    .search-item {
      display: flex;
      align-items: center;
      margin-right: 20px;
      .title {
        width: 80px;
      }
      .input-container{
        width: 300px;
        margin-right: 10px;
      }
    }
  }
}
</style>
